﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Caching;
using System.Web.Mvc;

namespace WebApplication1.Controllers
{
    public class HomeController : Controller
    {
        /// <summary>
        /// 数据缓存
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {

            string dataStr = DateTime.Now.ToLongTimeString();
            string text = "第一次输出时间:" + dataStr;//这里读取的是当前时间 ,刷新页面时这里会变化

            if (CacheExtension.GetCache("date") == null) //判断是否存在缓存,如果没有写入缓存,有直接读取
            {
                CacheExtension.SetCache("date", dataStr, DateTime.Now.AddSeconds(40), Cache.NoSlidingExpiration);//40秒后过期

                text += ",缓存后的数据=" + CacheExtension.GetCache("date");
            }
            else
            {
                text += ",缓存后的数据:" + CacheExtension.GetCache("date");
            }
            return Content(text);
        }

        public ActionResult inden2()
        {
            string ids = string.Empty;
            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}